package com.xyh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyh.dao.PermissionDao;
import com.xyh.dao.UserDao;
import com.xyh.po.Permission;
import com.xyh.po.User;
import com.xyh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:kyle
 * @Date:2020/12/23 - 14:10
 * @Project:spring_StudentsDormitoryManagementSystem
 * @Package:com.xyh.service.impl
 * @Version:1.0
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao,User> implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private PermissionDao permissionDao;

    @Override
    public User login(String username, String password) {

        User user = userDao.login(username, password);
        if(user != null){
            List<Permission> permissions = permissionDao.findPermissionsByUser(username);
            user.setPermissions(permissions);
        }

        return user;
    }
}
